<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	Cookie[] c=request.getCookies();
	if(c!=null){
		for(int i=0;i<c.length;++i){
			if(c[i].getName().equals("JOJUser")==true){
				response.sendRedirect("../index.jsp");
			}
		}
	}
%>
<title>用户登陆|JOJ在线评测系统</title>
<script type="text/javascript">
function login(){
	var username=document.getElementById("username").value;
	var password=document.getElementById("password").value;
	var ajax=new XMLHttpRequest();
	ajax.onreadystatechange=function(){
		if(ajax.readyState==4 && ajax.status==200){
		    var result=ajax.responseText;
		    if(result=="succes"){
		    	alert("登陆成功！");
		    	window.location="redirect.jsp?username="+username;
		    }else if(result=="username"){
		    	alert("用户名错误！");
		    }else if(result=="password"){
		        alert("密码错误！");
		    }
		}
	};
	ajax.open("post", "UserLogin", true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("username="+username+"&password="+password);
}

function reset(){
	document.getElementById("username").value="";
	document.getElementById("password").value="";
}
</script>
</head>
<body>
<center>
<jsp:include page="/common/header.jsp"></jsp:include>
<br/>
<table border="1">
	<tr>
		<td>用户名：</td>
		<td><input type="text" id="username" name="username" style="width: 350px;" /></td>
	</tr>
	<tr>
		<td>密码：</td>
		<td><input type="password" id="password" name="password" style="width: 350px;" /></td>
	</tr>
	<tr>
		<td><button onclick="login()">登陆</button></td>
		<td><button onclick="reset()">重置</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""></a></td>
	</tr>
</table>
</center>
</body>
</html>